package com.twu.biblioteca.Persistence;
import com.twu.biblioteca.library.items.LibraryItem;
import java.util.HashSet;
import java.util.Set;

/**
 * Created by aruna on 28/4/14.
 */
public class ItemsRepository<T extends LibraryItem> {
    private final Set<T> availableList=new HashSet<T>();

    public String ListItems()
    {
        String ItemListAsString="";
        for(LibraryItem item:availableList)
        {

            if(!item.isItemcheckedOut())
                ItemListAsString+=item;
        }


        if(ItemListAsString.equals(""))
            return "None";
        return ItemListAsString;
    }
    public void add(T object_to_add)
    {
        availableList.add(object_to_add);
    }
    public boolean isItemAvailable(String ISBN)
    {
        for(LibraryItem item:availableList)
            if((!item.isItemcheckedOut())&&(item.getId().equals(ISBN))) {
                return true;
            }
        return false;
    }
    public boolean isValidItem(String Id) {
        for (LibraryItem item : availableList)
            if (item.getId().equalsIgnoreCase(Id))
                return true;
        return false;
    }
    public LibraryItem getItemByID(String ISBN)
    {
        for(LibraryItem item:availableList)
        {
            if(item.getId().contentEquals(ISBN))
                return item;
        }
        return null;
    }



}
